package com.rfid.emergencywarehouse.adapter;

import android.view.View;
import android.widget.CompoundButton;

import com.rfid.emergencywarehouse.entity.BarcodeInfo;

import java.util.List;

public class MutilChoiceScanBarCodeAdapter extends ScanBarcodeAdapter{

    public MutilChoiceScanBarCodeAdapter(List<BarcodeInfo> data) {
        super(data);
    }

    @Override
    protected void bindView(MyHolder holder, int position, BarcodeInfo t) {
        BarcodeInfo barcodeInfo = mData.get(position);
        holder.barcode.setText("RFID编码：" + barcodeInfo.getBarcode());
//        holder.barcode.setText(barcodeInfo.getBarcode());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!selectable) {
                    return;
                }
                if (canSelect(barcodeInfo)) {
                    holder.select.toggle();
                }
            }
        });
        System.out.println("pos = " + position + ",select = "+ barcodeInfo.isSelect());
        holder.select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                System.out.println("onCheckedChanged isChecked = " + isChecked + ",pos = " + position);
                barcodeInfo.setSelect(isChecked);
                if (mListener != null) {
                    mListener.onSelect(barcodeInfo,isChecked);
                }
            }
        });
        holder.select.setChecked(barcodeInfo.isSelect());
        holder.select.setClickable(false);
        if (!selectable){
            holder.select.setVisibility(View.GONE);
        } else {
            holder.select.setVisibility(View.VISIBLE);
        }
    }

    protected boolean canSelect(BarcodeInfo barcodeInfo) {
        return true;
    }
}
